﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Navigation;
using GurLoader.ViewModel;
using NUnit.Framework;

namespace GurLoaderWPF.Test.ViewModel
{
    [TestFixture]
    public class LoginViewModelTests
    {
        [Test]
        public void CreateInstanceTest()
        {
            Uri currentUri = new Uri("http://www.something.com");
            var instance = new LoginViewModel(currentUri);

            Assert.IsNotNull(instance);
        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void CreateInstanceNullUriTest()
        {
            var instance = new LoginViewModel(null);
        }

        [Test]
        public void UriChangedEventTest()
        {
            Uri currentUri = new Uri("http://www.something.com");
            var instance = new LoginViewModel(currentUri);

            Assert.IsNotNull(instance);

            Uri newUri = new Uri("http://google.com");

            ManualResetEvent mre = new ManualResetEvent(false);
            instance.CurrentUriChanged += (sender, args) =>
            {
                mre.Set();
            };


            instance.NavigatedCommnad.Execute(newUri);

            Assert.IsTrue(mre.WaitOne(1000*3), "Timeout waiting for Uri Change callback.");

            Assert.AreNotEqual(instance.CurrentUri, currentUri);
        }

    }
}
